import { markRaw, type Component } from "vue";
import type { DetailMapItemType } from "@/components/CellGroup/types";
import { formatDate } from "@/utils";
import { ProcessTypeEnum } from "../approveList/constants";
import InquiryDetail from "./modules/InquiryDetail.vue";
import PurDetail from "./modules/PurDetail.vue";
import StampDetail from "./modules/StampDetail.vue";

/** 采购询比价定价流程审批详情映射 */
export const APPROVE_DETAIL_MAP: DetailMapItemType[] = [
	{ label: "物料号", field: "materialCode" },
	// { label: "物料名称", field: "materialName" },
	{ label: "规格", field: "specification" },
	{ label: "材质/品牌", field: "material" },
	{ label: "图号", field: "drawCode" },
	{ label: "单位", field: "countUnit" },
	{ label: "采购数量", field: "amount" },
	{ label: "单价(元)", field: "unitPrice" },
	{ label: "合计", field: "totalPrice" },
	{ label: "供应商名称", field: "supplierName" },
	{ label: "供应商单价", field: "supplierPrice" },
	{ label: "联系人", field: "contactName" }
];

/** 研发试制审批详情映射 */
export const PUR_APPROVE_DETAIL_MAP: DetailMapItemType[] = [
	{ label: "审批名称", field: "title", slotName: "title" },
	{ label: "申请人", field: "applyerName" },
	{ label: "公司名称", field: "companyName" },
	{ label: "项目名称", field: "projectName" },
	{ label: "项目负责人", field: "projecterName" },
	{ label: "申请类型", field: "applyType" },
	{ label: "是否电控研发部PCB试制", field: "pcbFlag" }
	// { label: "状态", field: "status", slotName: "status" }
];

/** 用章申请审批详情映射 */
export const STAMP_APPROVE_DETAIL_MAP: DetailMapItemType[] = [
	{ label: "审批名称", field: "title", slotName: "title" },
	{ label: "提交人", field: "createUserName" },
	{
		label: "提交时间",
		field: "createTime",
		formatter: (value: string) => {
			return formatDate(value, "YYYY-MM-DD", "-", true);
		}
	},
	// { label: "状态", field: "status", slotName: "status" },
	{ label: "提交人部门", field: "departName" },
	{ label: "经办人", field: "handlerName" },
	{ label: "印章类型", field: "sealType" },
	{ label: "印章所属公司", field: "companyName" },
	{ label: "用印数量", field: "sealCount" },
	{ label: "合同金额", field: "sealAmount" },
	{ label: "申请事由", field: "applyReason" },
	{ label: "图片", field: "imagePath", slotName: "imagePath" },
	{ label: "附件", field: "attachmentPath", slotName: "attachmentPath" }
];

/** 流程类型对应接口映射 */
export const APPROVE_TYPE_DETAIL_API_MAP: {
	[x in ProcessTypeEnum]: {
		title: string;
		methods: "POST" | "GET" | "DELETE" | "PUT";
		url: string;
		detailMap: DetailMapItemType[];
		component: Component;
	};
} = {
	[ProcessTypeEnum.INQUIRY]: {
		title: "采购询比价定价流程",
		url: "/mistake-api/api/quote/item/getById",
		methods: "POST",
		detailMap: APPROVE_DETAIL_MAP,
		component: markRaw(InquiryDetail)
	},
	[ProcessTypeEnum.PUR]: {
		title: "研发试制、采购申请流程",
		url: "/mistake-api/api/tech/pur/getById",
		methods: "POST",
		detailMap: PUR_APPROVE_DETAIL_MAP,
		component: markRaw(PurDetail)
	},
	[ProcessTypeEnum.STAMP]: {
		title: "用章使用申请",
		url: "/mistake-api/api/seal/apply/getById",
		methods: "GET",
		detailMap: STAMP_APPROVE_DETAIL_MAP,
		component: markRaw(StampDetail)
	}
};
